using System.Web.Profile;
using System.Web.Security;

namespace Marketplace.Mvc.Models
{
    public class ProfileModel : ProfileBase
    {
        private ProfileBase _profile = null;
 
        private ProfileModel(ProfileBase profile)
        {
            _profile = profile;
        }
        
        public static ProfileModel Current
        {

            get
            {
                var membershipUser = Membership.GetUser();
                return (ProfileModel) Create(membershipUser.UserName);
            }
        }

        public static ProfileModel CreateProfile(string username)
        {
            if (string.IsNullOrWhiteSpace(username))
                return null;

            return new ProfileModel(Create(username));
        }
        
        private const string TelephoneName = "Telephone";
        private const string MobileName = "Mobile";
        private const string AddressName = "Address";
        
        public string Telephone
        {
            get { return (string) _profile.GetPropertyValue(TelephoneName); }
            set { _profile.SetPropertyValue(TelephoneName, value);}
        }
        
        public string Mobile
        {
            get { return (string) _profile.GetPropertyValue(MobileName); }
            set { _profile.SetPropertyValue(MobileName, value); }
        }
        
        public string Address
        {
            get { return (string)_profile.GetPropertyValue(AddressName); }
            set { _profile.SetPropertyValue(AddressName, value); }
        }

        public override void Save()
        {
            _profile.Save();
        }
    }
}